jbuilder7+weblogic7下开发Servlet的配置问题? (200分)

  • 主题发起人 主题发起人 jeboo
  • 开始时间 开始时间
J

jeboo

Unregistered / Unconfirmed
GUEST, unregistred user!
本人刚开始学习jbuilder7来编程。我按照jbuilder7自带帮助中的指南开发servlet,web服务器是weblogic7(大家可以参看如下目录Jbuilder Help-Contents-Developing Web Application-Tutorials-Tutorials:Creating a Simple Servlet)。无论是weblogic的配置,还是生成Servlet的步骤都是按照指南说明。但是最后一步运行与发布Servlet时,weblogic被正确的启动了,但是系统默认生成的调用servlet的shtml文件却没有被运行起来。
请问这个问题出在哪里,是不是某个步骤错误勒,我真的很需要有人愿意告诉我。我的weblogic配置应该是没有问题的我成功的生成了一个SessionBean。
 
我记得我照着做过,没有问题。如果你把你的代码贴出来,我可以帮你测试一下。
 
我再试了一次,遇到了新问题,当输入Name of User时没问题,当不输入Name of User时
不能显示缺省的用户名User!而是仍为null。
比较原来按Jbuilder4做的例子,发现生成的文件有些不同。新文件如下所示:
文件Servlet1.java
package simpleservlet;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
public class Servlet1 extends HttpServlet {
static final private String CONTENT_TYPE = "text/html;
charset=BIG5";
//Initialize global variables
int connections = 0;
public void init() throws ServletException {
}
//Process the HTTP Get request
public voiddo
Get(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//Name of User
String userName = request.getParameter("UserName");
if (userName == null) {
userName = "USER";
}
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
out.println("<font color=/"green/">");
out.println("<p>The servlet has received a GET. This is the reply.</p>");
out.println("</font>");
}
//Process the HTTP Post request
public voiddo
Post(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//Name of User
String userName =null;
userName = request.getParameter("UserName");
if (userName == null) {
userName = "USER";
}
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head><title>Servlet1</title></head>");
out.println("<body>");
out.println("<p>The servlet has received a POST. This is the reply.</p>");
out.println("<p>Thanks for visiting, ");
out.println(request.getParameter("UserName"));
out.println("<p>");
out.println("Hello World - my first Java servlet program!");
out.println("<p>You are visitor number ");
out.println(Integer.toString(++connections));
out.println("</body></html>");
}
//Clean up resources
public void destroy() {
}
}
文件Servlet1.shtml
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=BIG5">
<title>
Servlet1
</title>
</head>
<body>
<form action="/simpleservletwebapp/servlet1" method="post">
<p>Name of User <input type="text" name="UserName"></p>
<p>press Submit to post to servlet Servlet1</p>
<p><input type="submit" name="Submit" value="Submit">
<input type="reset" value="Reset"></p>
</form>
<p>Output from servlet <code>Servlet1</code> GET:</p>
<hr>
<servlet
codebase=""
code="simpleservlet.Servlet1.class"
>
<param name="UserName" value="USER" />
</servlet>
<hr>
</body>
</html>
注意几点:
1.语句out.println(request.getParameter("UserName"));似应为
out.println(userName);
2.不知道为什么?同样的代码
String userName =null;
userName=request.getParameter("UserName");
if (userName==null) {
userName="USER";
}
在doGet中没有问题,在doPost中不能正确执行,单步执行时userName=""但跳过了
userName="USER";如果将语句“ if (userName==null) {“改为“ if (userName=="") {“
还是同样的问题。
修改如下:
String userName =null;
userName=request.getParameter("UserName");
if (userName.length()==0) {
userName="USER";
}
就可以了。
3.server设成tomcat或weblogic都可以运行,但是为weblogic时,窗口中出现如下信息:
<Included resource or file "/simpleservletwebapp/servlet/simpleservlet.Servlet1"
not found from requested resource "/simpleservletwebapp/Servlet1.shtml".>
但不影响得到正确的结果。
 

Similar threads

D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
后退
顶部