how do i find html of struts? - java

I am really new and not familiar with this...I am trying to edit this folder with a ton of files in it including .xml....I need to find the html part but it is using "struts" and I don't know much about it other than it being a Java MVC framework...
How can I find the html part? the URL is http://localhost:8080/ContractView.do
I searched inside 1 of the xml file and found this which might be of use:
<action name="DashBoardForm" path="/DashBoard" type="com.manageengine.servicedesk.dashboard.action.DashBoardAction">
<forward name="viewDashBoard" path="/dashboard/Dashboard.jsp"/>
</action>
Any Ideas on how I can get the html?
I want to basically add an extra option to the menu.
I am really new to this and just trying to add an extra menu to the navigation bar so that I can embed php files in it that it will link to..
it is a software, can be downloaded at
http://www.manageengine.com/products/service-desk/download.html

/dashboard/Dashboard.jsp should be a view page containing html. In Struts the struts-config.xml file dictates which request gets served by which servlet. In your case, ContactView.do should have a mapping to an action class. Look for the xml config line in that file that contains path="/ViewContact".
In the actual jsp page you may see a mix of struts constructs - (ie. s:<some_tag>), JSTL (ie. c:<some_tag>, and pure html). However, they all obviously get translated to HTML when you are viewing it in a client (ie. browsers).
Another thing you may want to check out is whether it is using tiles. A lot of times the view page may be defined in the tiles-defition.xml file. So that may be another place for you to look where ContactView jsp may be defined at. If it is using tiles then you will find the name of tile definition in the struts-config.xml and then find the actual JSP path in the tiles-definition.xml.
UPDATE
After you added the link to struts-config.xml, I can tell you exactly which JSP your request goes to which is originally what you asked in your post.
Take a look at the following snippet:-
<action name="ContractViewForm" path="/ContractView" scope="request" type="com.adventnet.servicedesk.contract.action.ContractViewAction" input="ContractListView.jsp">
<forward name="contractListView" path="/contract/ContractListView.jsp?task=ContractListView"/>
<forward name="newContract" path="/contract/ContractDef.jsp?task=ContractDef"/>
</action>
<form-bean name="ContractViewForm" type="com.adventnet.servicedesk.contract.form.ContractViewForm"/>
From this snippet as you can see depending on how the page was forwarded from the previous action (ie. form submit) it will either go to /contract/ContractListView.jsp or /contract/ContractDef.jsp . The backing action class is com.adventnet.servicedesk.contract.action.ContractViewAction which is the class where all the business logic processing starts. The form is com.adventnet.servicedesk.contract.form.ContractViewForm where all the form fields are stored and it is at requqest scope.
Hope this helps!

Related

small program on struts2 and jsp

i have done some learning on struts based on one project that i got.Now i have to build 2 to 3 struts jsp pages.
I have following scenario..
<action name="BackAction" class="ClassnamePath">
<result name="user_validated" type="redirectAction">
<param name="actionName">welcome</param>
</result>
<result name="user_profile_found_in_database">/resources/userprofile.jsp</result>
what does param will tell..what is the significance of param(i do not know about this)
my scenario is like this In the class(ClassnamePath) i have done one java program which bring the data from the database and put the values in the userprofile.java(for example the userprofile has variable members like name,email,phone,pin)
that values are come from database and stored in the object of the class userprofile.
i have a task that whenever the result "user_profile_found_in_database" has been done those values should be presented in the jsp as result of the "user_profile_found_in_database"
Is the result "user_profile_found_in_database" that i mentioned in the action tag correct?
the jsp page should be having userprofile with labels as the fields of the userprofile and values should be in the text boxes.
i do not know anything about jsp pages...even web programming..but i am learning on my own..(i am having one doubt how jsp pages are different from struts jsp pages)
with the above tasks i can learn lot in struts and jsp..
Please give some knowledge on this to build further.
JSP pages are not way different than simple JSP pages and in short Struts2 will provides a set of tags which will help we as an end developer to build application fast as these tags provides a easy to access functionality about various features S2 providing, few of them are
Accessing Value Stack using OGNL
Data conversion from server to client and other way around
Features to access other things like request/response/session in most easy and flexible way.
In end when you browser will render the jsp page it will be simple HTML and S2 tags one using in there application will be converted to the HTML as browser will understand HTML.
regarding second part accessing user profile in your jsp do the following gin your Action class
Create an instance of UserProfile in you action class
Create getter and setter for the UserProfile instance
Fill the value in the user-profile (you will fetch that from your DB call)
when your action will send back the response, S2 will place the user-profile instance on top of Value stack and we can access its properties using S2 tags like
<s:textfield name="user_name" value="%{name}"/>
<s:textfield name="user_age" value="%{age}"/>
here name and age are the properties of your user-profile.param in your redirectAction configuration is being used to provide parameters to the result, for more information about what parameters do please read official document.
redirect-action-result
.
Ya i got your question like this,
what is the exact meaning of param tag?
param tag means:
Struts 2 “param” tag is used to parametrize other tags. However, when you declared the “param” tag, the “parameter value” can be define in two ways :
“value” attribute
Text between the start and end of “param” tag.
For Example:
<param name="fruit">Banana</param>
<param name="fruit" value="Banana"/>
In Your example the 1st case i think
Here see this web site it is present complete structure...
http://www.mkyong.com/struts2/struts-2-param-tag-example/

Struts 2: Action result. How show in browser address line link on jsp?

For example on our index.jsp contains only one link:
Your Book
In browser on index.jsp page I see this link:
http://localhost:8080/project/viewBook.action
when I click on this link opened page and in browser address line I see next address:
http://localhost:8080/project/viewBook.action
struts.xml contains next lines for action listTicket:
<action name="viewBook" class="BookAction" method="view">
<result>pages/book.jsp</result>
</action>
My question: what I must change, that instead viewBook.action in browser I see link to the Page:
http://localhost:8080/project/book.jsp
I try set for result tag type="redirect". But in this case - page empty.
You won't see the backing view file shown in the URL, nor should you want to. View mechanics are an abstraction and not shown in essentially all MVC frameworks.
You'll see viewBook.action (assuming default action extension) if you redirect to the action using a "redirectAction" result type. This is the desired URL.
You should not do this. You want the url to link to your controller and not your jsp.

In Struts 1, how to specify input page URL and not path to JSP

I have a very annoying problem with Struts. The input page is located under an URL similar to this: /news/send/. URLs of this type are required by the CMS we're using.
In struts-config.xml, as action input I can only specify the path to the JSP file, e.g.
<action path="/send" type="org.example.SendAction" name="sendForm" scope="request"
input="/WEB-INF/jsp/send.jsp" validate="true" />
The part that bugs me is input="/WEB-INF/jsp/send.jsp". I need it to be something like:
input="/news/send/" but it just gives me a 404 when I try that. It seems to require a path to a JSP, and the JSP as such does not exist, it's generated by the CMS when the above URL is accessed.
Since this page is needed only if validation is enabled, I can disable the validation and validate manually in the action, but I'd much rather avoid that.
Any ideas?
Thanks for any insight.
I learned in the mean time that Struts can not forward to a resource that does not yet exist, so using redirects is the only option in such cases, and since validation errors always result in a forward, it's impossible to use the validation mechanism here.

How to JSP display multiple page with one layout (Example index.jsp?page=about display about.jsp)

I new in JSP, i have a problem with JSP
in php i use
$page=$_GET["page"]
for display multiple page for one layout it mean i have index , it display layout and when i click on menu go to about us the index url = index.jsp?page=about
in PHP when i declare $page above and next step i do
Switch($page){
case 1:about
include 'aboutus.php'
case 2:news
include 'news.php'
}
How can i do it ?
How jsp can do the same way php to display multiple page in 1 layout
Use jsp:include.
<jsp:include page="/WEB-INF/${param.page}.jsp" />
And pass ?page=news or ?page=about, etc as parameter. The ${param.page} prints the outcome of request.getParameter("page"). You can prevent direct access to JSP files (by entering URL in browser address bar) by placing JSP files in /WEB-INF folder.
See also:
Basic JSP/Servlet tutorials
Hidden features of JSP/Servlet
How to avoid Java code in JSP
nowadays you use "templates" of Java Server Faces (JSF) for this approach. When you use JSP, you actually don't use the same concept as in PHP. You'd better use the MVC concept. But to answer your question, you could probably achieve this with the include tag http://java.sun.com/products/jsp/tags/11/syntaxref1112.html and control it with JSTL:
http://www.java2s.com/Code/Java/JSTL/JSTLiftag.htm

Prevent XSS attempts on a Tomcat/Struts 1 web application (without source code)

A 3rd party web application has a cross-scripting security issue. There is one page with three fields which are not sanitized. The vendor will not provide a timely fix and I need to.
The application is running in Tomcat and uses Struts 1. The action for the bad page looks like this:
<action
path="/badpage"
type="com.badvendor.BadAction"
name="badForm"
scope="request"
validate="true"
input="/otherbadpage.do">
<forward name="failure" path="/otherbadpage.do"/>
<forward name="success" path="/otherbadpage.do"/>
</action>
I do not have the source code for the action class.
What is the easiest way to get between the request and the action to sanitize the input (or even just cause an error on bad input)?
You can:
Change the mapping to point to a different action (yours). Forward control to the action in question after sanitizing input.
Write a servlet filter to intercept that particular URI.

Categories

Resources